<template>
  <div class="wrapper">
    <draft-article-list :articles=articles class="draft-article-list"
    @fetchArticleAbstracts="fetchArticleAbstracts"></draft-article-list>
  </div>
</template>

<script>
import DraftArticleList from '@/components/DraftArticleList.vue';

  export default {
    components: {
      DraftArticleList,
    },
    data() {
      return {
        articles: [],
        articlePage: 0,
      }
    },
    methods: {
      fetchArticleAbstracts() {
        this.$fetch({
          name: 'article draft',
          url: 'creator/manage/article/draft',
          method: 'POST',
          data: {
            page: ++this.articlePage
          }
        }).then(res => {
          if(res.data.success) {
            if(res.data.object.length) this.articles = this.articles.concat(res.data.object);
            else this.articlePage--;
          } else {
            this.$alert({
              type: 'error',
              content: '获取草稿失败'
            });
            this.articlePage--;
          }
        }).catch(error => {
          this.$alert({
            type: 'error',
            content: '获取草稿失败'
          })
          this.articlePage--;
        })
      }
    },
  }
</script>

<style lang="less" scoped>
</style>